// pages/evaluate/evaluate.js
const getdata = require("../../tool/GetDate.js")
const util = require("../../utils/util.js")
var app = getApp();
var orderData = {};
var selectArray = [];
var idea = "";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    evaluate: [],
    idea: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  getEvaluationOrder: function() {
    let that = this;
    getdata.getdata({
      url: "gbt/Evaluation/EvaluationOrder/" + app.globalData.myUserData.userID + "/",
      data: app.globalData.myUserData.districtID,
      success: function(res) {
        console.log(res.root);
        if (res.root) {
          that.setData({
            evaluate: res.root.data,
          });
        }
      },
    });
  },

  optEvaluationOrder: function(data) {
    let that = this;
    getdata.postdata({
      url: "gbt/Evaluation/OptEvaluationOrder",
      data: JSON.stringify(data),
      success: function(res) {
        console.log(res.root);
        if (res.root) {
          wx.showToast({
            title: `${res.root.message}`,
            icon: "none",
            duration: 3000,
          })

          if (res.root.state) {
            that.setData({
              idea: res.root.idea
            })
            //添加完成 刷新一下食堂菜品质量评价单
            that.getEvaluationOrder();
          } else {
            orderData = {};
            selectArray = [];
            idea = "";
          }

        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    orderData = {};
    selectArray = [];
    idea = "";
    this.getEvaluationOrder();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  // /**
  //  * 用户点击右上角分享
  //  */
  // onShareAppMessage: function() {
    
  // },

  bindTextAreaBlur: function(e) {
    idea = e.detail.value;
    console.log(idea);
  },

  radioChange: function(e) {
    let selectData = {};
    selectData["ectrid"] = e.detail.value;
    selectArray.push(selectData);
    console.log(selectArray);
  },

  onConfirm: function(e) {
    let that = this;
    wx.showModal({
      title: '温馨提示',
      content: '一天只能提交一次评价且无法修改，是否确定提交！',
      confirmText: '是',
      cancelText: '否',
      success(res) {
        if (res.confirm) {
          orderData["userID"] = app.globalData.myUserData.userID;
          orderData["districtID"] = app.globalData.myUserData.districtID;
          orderData["idea"] = idea;
          orderData["evaluate"] = selectArray;
          console.log(orderData);
          that.optEvaluationOrder(orderData);
        }
      }
    })
  }
})